CSharpTest.Net
Compare Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > KeyValueComparer<TKey,TValue> Class : Compare Method

x
y

Glossary Item Box

Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

Syntax

Visual Basic (Declaration) 
Public Function Compare( _
   ByVal x As KeyValuePair(Of TKey,TValue), _
   ByVal y As KeyValuePair(Of TKey,TValue) _
) As Integer
C# 
public int Compare( 
   KeyValuePair<TKey,TValue> x,
   KeyValuePair<TKey,TValue> y
)

Parameters

x
y

Example

Library/Library.Test/TestOrderedEnumeration.cs

C#Copy Code
KeyValueComparer<int, int> cmp = new KeyValueComparer<int, int>();
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, cmp.Comparer));
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, KeyValueComparer<int, int>.Default.Comparer));

Assert.AreEqual(-1, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(2, 1)));
Assert.AreEqual(0, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(1, 2)));
Assert.AreEqual(1, cmp.Compare(new KeyValuePair<int, int>(2, 1), new KeyValuePair<int, int>(1, 1)));
VB.NETCopy Code
Dim cmp As New KeyValueComparer(Of Integer, Integer)()
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], cmp.Comparer))
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], KeyValueComparer(Of Integer, Integer).[Default].Comparer))

Assert.AreEqual(-1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(2, 1)))
Assert.AreEqual(0, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(1, 2)))
Assert.AreEqual(1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(2, 1), New KeyValuePair(Of Integer, Integer)(1, 1)))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys